<template>
  <section class="finance-and-etax-info">
    <el-tabs value="base" class="tab">
      <el-tab-pane label="财税初始化信息" name="base"></el-tab-pane>
    </el-tabs>
    <el-form
      ref="form"
      :model="form"
      :validate-on-rule-change="false"
      label-width="140px"
      size="mini"
      class="form-section"
    >
    <el-form-item label="资产负债表" prop="balanceStatementFileId">
        <el-upload
          :multiple="false"
          :limit="1"
          :with-credentials="true"
          :on-remove="removeBalanceStatementFile"
          :on-exceed="onExceed"
          :data="{ key: 'yearBalanceSheetFileId' }"
          accept=".xlsx,.xls"
          action="YEAR_FIRST_BALANCE_SHEET"
          :http-request="uploadFile"
          class="upload-item"
        >
          <el-button size="small" type="primary"
            >点击上传【资产负债表】excel</el-button
          >
        </el-upload>
      </el-form-item>
     <!-- <el-form-item label="利润表" prop="incomeStatementFileId">
        <el-upload
          :multiple="false"
          :limit="1"
          :with-credentials="true"
          :on-remove="removeIncomeStatementFile"
          :on-exceed="onExceed"
          :data="{ key: 'incomeStatementFileId' }"
          accept=".xlsx,.xls"
          action="/upload/incomeStatement"
          :http-request="uploadFile"
          class="upload-item"
        >
          <el-button size="small" type="primary"
            >点击上传【利润表】excel</el-button
          >
        </el-upload>
      </el-form-item> -->
      <el-form-item label="期初科目余额表" prop="subjectStatementFileId">
        <el-upload
          :multiple="false"
          :limit="1"
          :with-credentials="true"
          :on-remove="removeSubjectBalanceStatementFile"
          :on-exceed="onExceed"
          :data="{ key: 'subjectBalanceSheetFileId' }"
          accept=".xlsx,.xls"
          action="PERIOD_FIRST_SUBJECT_BALANCE_SHEET"
          :http-request="uploadFile"
          class="upload-item"
        >
          <el-button size="small" type="primary"
            >点击上传【科目余额表】excel</el-button
          >
        </el-upload>
      </el-form-item>
      <el-form-item label="现金流量表" prop="cashFlowSheetFileId">
        <el-upload
          :multiple="false"
          :limit="1"
          :with-credentials="true"
          :on-remove="removeCashFlowSheet"
          :on-exceed="onExceed"
          :data="{ key: 'cashFlowSheetFileId' }"
          accept=".xlsx,.xls"
          action="PERIOD_FIRST_CASH_SHEET"
          :http-request="uploadFile"
          class="upload-item"
        >
          <el-button size="small" type="primary"
            >点击上传【现金流量表】excel</el-button
          >
        </el-upload>
      </el-form-item>
    </el-form>
    <section class="discount-policy">
      <el-form label-width="140px" size="mini">
        <el-form-item label="税收优惠政策">
          <el-select
            placeholder="请选择"
            v-model="form.discountPolicy"
            :multiple="true"
            size="mini"
          >
            <el-option
              v-for="item in discountPolicyList"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div class="explain">
        若客户享受特殊的税收优惠政策(例如小微企业/高新企业等)，请在此输入，全国性的政策优惠将由系统自动更新。
      </div>
    </section>
  <!--  <section class="discount-policy">
      <div class="start-amount-record-title">期初缴费记录</div>
      <div class="amount-record-form">
        <el-form
          ref="start-record-form"
          :model="startRecordForm"
          :validate-on-rule-change="false"
          label-width="140px"
          size="mini"
          class="form-section"
        >
          <el-form-item label="增值税" prop="companyAddedTax" type="number">
            <el-input
              type="number"
              v-model="startRecordForm.companyAddedTax"
              :disabled="startAmountRecordDisabled"
              placeholder="请输入"
            >
            </el-input>
          </el-form-item>
          <el-form-item label="所得税" prop="companyIncomeTax" type="number">
            <el-input
              type="number"
              v-model="startRecordForm.companyIncomeTax"
              :disabled="startAmountRecordDisabled"
              placeholder="请输入"
            >
            </el-input>
          </el-form-item>
          <el-form-item label="印花税" prop="stampTax" type="number">
            <el-input
              type="number"
              v-model="startRecordForm.stampTax"
              :disabled="startAmountRecordDisabled"
              placeholder="请输入"
            >
            </el-input>
          </el-form-item>
          <el-form-item label="城建及附加税" prop="urbanAppendTax" type="number">
            <el-input
              type="number"
              v-model="startRecordForm.urbanTax"
              :disabled="startAmountRecordDisabled"
              placeholder="请输入"
            >
            </el-input>
          </el-form-item>
          <el-form-item label="社保" prop="social">
            <el-input
              type="number"
              v-model="startRecordForm.social"
              :disabled="startAmountRecordDisabled"
              placeholder="请输入"
            >
            </el-input>
          </el-form-item>
          <el-form-item label="个税代缴" prop="incomeTax">
            <el-input
              type="number"
              v-model="startRecordForm.incomeTax"
              :disabled="startAmountRecordDisabled"
              placeholder="请输入"
            >
            </el-input>
          </el-form-item>
        </el-form>
      </div>
    </section> -->
  </section>
</template>

<script>
import map, {getFileType} from "@/components/map";
import utiles, { getPreMonth } from '@/components/utiles';

export default {
  data() {
    return {
      discountPolicyList: map.discountPolicy,
      form: {
        // 上传文件的校验
        balanceStatementFileId: "",
        incomeStatementFileId: "",
        // bankStatementFileId: '',
        discountPolicy: [],
      },
      startRecordForm: {
        month: getPreMonth(),
      },
      startAmountRecordDisabled: false,
    };
  },
  props:{
    cName: {
      type: String, 
      value: null
    }
  },
  watch:{
    cName(n, o){
      console.log("cName:", n);      
    }
  },
  methods: {
    /**
     * 获取数据
     */
    getValue() {
      return {
        form: this.form,
        taxesStandardInfo: this.startRecordForm,
      };
    },
  

    /**
     * 超出最大上传数
     */
    onExceed() {
      this.$message.error("当前文件已上传，如需更新请删除后再重新上传");
    },

    /**
     * 上传文件
     *
     * @param {Object} fileData 文件数据
     */
    uploadFile(fileData) {
      const formData = new FormData();
      // 键值
      formData.append("file", fileData.file);
      formData.append('cName', this.cName);
      formData.append('fileType', getFileType(fileData.action));
      formData.append('fileName', fileData.file.name);
      this.$http
        .post("/upload/file", formData, {
          headers: {
            "Content-Type": "multipart/form-data",
          }
        })
        .then((res) => {
          this.form[fileData.data.key] = res.data.fileId;
        })
        .catch((err) => {
          console.error(err);
        });
    },

    /**
     * 移除
     */
    removeBalanceStatementFile() {
      this.form.yearBalanceSheetFileId = "";
    },

    /**
     * 移除
     */
    removeIncomeStatementFile() {
      this.form.incomeStatementFileId = "";
    },

    removeSubjectBalanceStatementFile(){
      this.form.subjectBalanceSheetFileId = "";
    },

    removeCashFlowSheet(){
      this.form.cashFlowSheetFileId = "";
    }

  },
};
</script>

<style lang="less">
@import "../../assets/var.less";
.finance-and-etax-info {
  .form-section {
    display: flex;
    flex-wrap: wrap;
    .el-form-item {
      flex: 1;
      min-width: 47%;
      max-width: 47%;
      .el-select,
      .el-upload {
        display: block;
      }
    }
  }
  .discount-policy {
    .el-form-item {
      max-width: 99%;
    }
    .el-select {
      width: 543px;
    }
    .explain {
      padding-left: 43px;
    }
  }
  .explain {
    // border-top: 1px solid #E4E7ED;
    // padding: 10px 0 5px 0;
    padding-bottom: 10px;
    color: @color-grey-low;
    font-size: 12px;
    line-height: 1.2em;
  }
  .start-amount-record-title {
    padding: 30px 0 20px;
    font-weight: bold;
    font-size: 15px;
  }
}
</style>
